package com.itheima.health.h5.controller;

import com.itheima.health.entity.Result;
import com.itheima.health.service.OrderSettingService;
import com.itheima.health.utils.poi.POIUtils;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Map;


@RestController
public class OrdersettingController {

    @Reference
    OrderSettingService orderSettingService;

    @PostMapping("ordersetting/importOrderSettings")
    public Result importOrderSettings(@RequestParam("excelFile") MultipartFile file) {
        try {
            List<String[]> list = POIUtils.readExcel(file);
            orderSettingService.importOrderSettings(list);
            return new Result(true);
        } catch (IOException e) {
            e.printStackTrace();
            return new Result(false);
        }
    }

    @GetMapping("ordersetting/findSettingData/{year}/{month}")
    public Result findSettingData(@PathVariable("year") String year,@PathVariable("month") String month){
        try{
            Map map =orderSettingService.findSettingData(year,month);
            return  new Result(map);
        }catch (Exception e){
            e.printStackTrace();
            return  new Result(false);
        }
    }

    @PutMapping("ordersetting/updateNumberByOrderdate/{number}/{orderDate}")
    public Result updateNumberByOrderdate(@PathVariable("number") int number,@PathVariable("orderDate") String orderDate){


       return new Result(orderSettingService.updateNumberByOrderdate(number,orderDate));
    }



}

